/*
 * Created by JFormDesigner on Wed Jul 06 10:17:49 CST 2022
 */

package View.PublicWindow;

import java.awt.*;
import javax.swing.*;

/**
 * @author Brainrain
 */
public class WaitingPanel extends JPanel {

    ImageIcon icon;
    private static final int PIC_NUM = 4;

    public WaitingPanel() {
        initComponents();
        icon = new ImageIcon("src/main/resources/waiting" + (int)(1 + Math.random() * (PIC_NUM)) + ".gif");
    }

    public void RandomPic() {
        System.out.println((int)(Math.random() * (PIC_NUM)));
        icon = new ImageIcon("src/main/resources/waiting" + (int)(Math.random() * (PIC_NUM)) + ".gif");
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        //下面这行是为了背景图片可以跟随窗口自行调整大小，可以自己设置成固定大小
        g.drawImage(icon.getImage(), 0, 0,this.getWidth(), this.getHeight(), this);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();

        //======== this ========
        setLayout(null);

        //---- label1 ----
        label1.setText("\u8ba1\u7b97\u4e2d\uff0c\u8bf7\u7b49\u5f85");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 20f));
        label1.setHorizontalAlignment(SwingConstants.CENTER);
        label1.setForeground(new Color(51, 153, 255));
        add(label1);
        label1.setBounds(0, 0, 260, 85);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < getComponentCount(); i++) {
                Rectangle bounds = getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            setMinimumSize(preferredSize);
            setPreferredSize(preferredSize);
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
